package com.example.java_gobang.game;

import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketSession;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class OnlineUserManager {
    private ConcurrentHashMap<Integer, WebSocketSession> gameRoom = new ConcurrentHashMap<>();
    private ConcurrentHashMap<Integer,WebSocketSession> gameMatch = new ConcurrentHashMap<>();
    public void enterGameRoom(int userId,WebSocketSession session){
        gameRoom.put(userId,session);
    }
    public void exitGameRoom(int userId){
        gameRoom.remove(userId);
    }
    public WebSocketSession getFromRoom(int userId){
        return gameRoom.get(userId);
    }
    //进入游戏房间
    public void enterGameMatch(int userId,WebSocketSession session){
        gameMatch.put(userId,session);
    }
    public void exitGameMatch(int userId){
        gameMatch.remove(userId);
    }
    public WebSocketSession getFromMatch(int userId){
        return gameMatch.get(userId);
    }
}
